Namespace CNG
    Public Class Supervisor
        Private _CodigoCD As String
        Private _Codigo As Integer
        Private _Nombre As String
        Private _Activo As Boolean
        Private _Telefono As String
        Public Property CodigoCD() As String
            Get
                Return _CodigoCD
            End Get
            Set(ByVal value As String)
                If _CodigoCD = value Then
                    Return
                End If
                _CodigoCD = value
            End Set
        End Property
        Public Property Codigo() As Integer
            Get
                Return _Codigo
            End Get
            Set(ByVal value As Integer)
                If _Codigo = value Then
                    Return
                End If
                _Codigo = value
            End Set
        End Property

        Public Property Nombre() As String
            Get
                Return _Nombre
            End Get
            Set(ByVal value As String)
                If _Nombre = value Then
                    Return
                End If
                _Nombre = value
            End Set
        End Property
        Public Property Activo() As Boolean
            Get
                Return _Activo
            End Get
            Set(ByVal value As Boolean)
                If _Activo = value Then
                    Return
                End If
                _Activo = value
            End Set
        End Property
        Public Property Telefono() As String
            Get
                Return _Telefono
            End Get
            Set(ByVal value As String)
                If _Telefono = value Then
                    Return
                End If
                _Telefono = value
            End Set
        End Property

        Public Sub Agregar()

            Dim comando As New CAD.Supervisor.Supervisor_INSERT(CAD.BaseDatos.Conexion)

            comando.ExecuteNonQuery(Me.CodigoCD, _
                                    Me.Codigo, _
                                    Me.Nombre, _
                                    Me.Activo, _
                                    Me.Telefono)

        End Sub

        Public Sub Modificar()

            Dim comando As New CAD.Supervisor.Supervisor_UPDATE(CAD.BaseDatos.Conexion)

            comando.ExecuteNonQuery(Me.CodigoCD, _
                                    Me.Codigo, _
                                    Me.Nombre, _
                                    Me.Activo, _
                                    Me.Telefono)
        End Sub

        Public Shared Function GenerarCodigo(ByVal CodigoCD As String) As Integer

            Dim Comando As New CAD.Supervisor.Supervisor_NEW_CODE(CAD.BaseDatos.Conexion)
            Dim Tabla As New DataTable

            Comando.LoadTable(Tabla, CodigoCD)

            Return Tabla.Rows(0).Item("Codigo")

        End Function

        Public Shared Function ListadoSupervisor(ByVal CodigoCD As String, ByVal Codigo As System.Nullable(Of Integer)) As DataTable

            Dim Comando As New CAD.Supervisor.Supervisor_SELECT(CAD.BaseDatos.Conexion)
            Dim Tabla As New DataTable

            Comando.LoadTable(Tabla, CodigoCD, Codigo)

            Return Tabla

        End Function
        Public Shared Function GetSupervisor(ByVal CodigoCD As String, ByVal Codigo As Integer) As Supervisor

            Dim Comando As New CAD.Supervisor.Supervisor_SELECT(CAD.BaseDatos.Conexion)
            Dim Tabla As New DataTable
            Dim miSupervisor As New CNG.Supervisor

            Comando.LoadTable(Tabla, CodigoCD, Codigo)

            If Tabla.Rows.Count > 0 Then

                miSupervisor.CodigoCD = Tabla.Rows(0).Item("CodigoCD")
                miSupervisor.Codigo = Tabla.Rows(0).Item("Codigo")
                miSupervisor.Nombre = Tabla.Rows(0).Item("Nombre")
                miSupervisor.Activo = Tabla.Rows(0).Item("Activo")
                miSupervisor.Telefono = Tabla.Rows(0).Item("Telefono")

                Return miSupervisor

            Else
                Return Nothing
            End If

        End Function

    End Class
End Namespace

